package cn.weiyuanbiao.DbGeneralCore.beetl;

import java.util.List;

import org.apache.log4j.Logger;
import org.beetl.core.Context;
import org.beetl.core.Function;

import cn.weiyuanbiao.DbGeneralCore.entity.ClassFieldEntity;
import cn.weiyuanbiao.DbGeneralCore.util.StringUtil;

/** set 和 get 方法的编写
 */
public class SetAndGetMethod implements Function {

	private static Logger log = Logger.getLogger(SetAndGetMethod.class);

	public Object call(Object[] arg, Context context) {
		List<ClassFieldEntity> dbcs = (List<ClassFieldEntity>) arg[0];
		StringBuilder sb = new StringBuilder("\n");
		for (ClassFieldEntity classFieldEntity : dbcs) {
			String fieldType = classFieldEntity.getFieldType();
			String fieldName = classFieldEntity.getFieldName();
			String firstLowerFieldName = StringUtil.toLowerCaseFirstOne(fieldName);
			String firstUpperFieldName = StringUtil.toUpperCaseFirstOne(fieldName);
//			String fieldNote = classFieldEntity.getFieldNote();
//			sb.append("	\/** get" + fieldNote + " *\/ \n");
			sb.append("\n");
			sb.append("	public " + fieldType + " get" + firstUpperFieldName + "() {\n");
			sb.append("		return " + firstLowerFieldName + ";\n");
			sb.append("	}\n\n");
//			sb.append("	\/** set" + fieldNote + " *\/ \n");
			sb.append("	public void set" + firstUpperFieldName + "(" + fieldType + " " + firstLowerFieldName + ") {\n");
			sb.append("		this." + firstLowerFieldName + " = " + firstLowerFieldName + ";\n");
			sb.append("	}\n");
		}
		return sb.toString();
	}


}
